package service;

import dao.ImplementNote;
import pojo.Note;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/addNoteServlet")
public class AddNoteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String usename=req.getParameter("usename");
        String title=req.getParameter("title");
        String content=req.getParameter("content");
        String type=req.getParameter("type");
        Note noteadd=new Note();
        noteadd.setStyle(0);
        noteadd.setTitle(title);
        noteadd.setContent(content);
        noteadd.setType(type);
        noteadd.setUsename(usename);
        ImplementNote implementNote=new ImplementNote();
        implementNote.addNote(noteadd);
        resp.sendRedirect(req.getContextPath()+"/user_notes.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
